<script type="text/javascript">
$(function(){
	var conta="<option value=''>请选择</option>";
	var contb="<option value=''>请选择</option>";
	var contc="<option value=''>请选择</option>";
	$.post("appChargeDef/showBaseInfo",function(json){
		for(var i=0;i<json.cdProDefinitions.length;i++){
			conta+="<option value="+json.cdProDefinitions[i].cardpCode+">"+json.cdProDefinitions[i].cardpName+"</option>"
		}
		for(var i=0;i<json.appClassifications.length;i++){
			contb+="<option value="+json.appClassifications[i].appKindId+">"+json.appClassifications[i].appKindName+"</option>"
		}
		for(var i=0;i<json.appKinds.length;i++){
			contc+="<option value="+json.appKinds[i].appType+">"+json.appKinds[i].appName+"</option>"
		}
		$("select[name='appType']").html(contc);
		$("select[name='appKindId']").html(contb);
		$("select[name='cardpCode']").html(conta);
		$.post("appChargeDef/getChargeDefInfo",addOrUpdateChargeDef,"json")
	},"json")
	
});
 
 function addOrUpdateChargeDef(json){
	 if(json!=null){
		 $("input[name='flag']").val("1")//修改标识
		 $("input[name='feeRuleId']").val(json.feeRuleId);
		 $("input[name='feeRulesId']").val(json.feeRulesId);
		 $("input[name='feeItemName']").val(json.feeItemName);
		 $("input[name='feeBln']").val(json.feeBln);
		 $("input[name='validStartDate']").val(getDate(json.validStartDate));
		 $("input[name='validEndDate']").val(getDate(json.validEndDate));
		 $("select[name='appType']").find("option").each(function(n,item){
			 if(json.appName==$(this).text()){
				 $(this).attr("selected","selected");
				 $(this).parent().attr("disabled",true);
			 }				 			 
		 })
		 if(json.appName==null){
			 var cont="<option value=''>无需选择应用</option>";
			 $("select[name='appType']").html(cont)
			 $("select[name='appKindId']").html(cont)
		 }
		 $("select[name='appKindId']").find("option").each(function(n,item){
			 if(json.appKindName==$(this).text()){
				 $(this).attr("selected","selected");
				 $(this).parent().attr("disabled",true);
			 }
		 })
		 $("select[name='feeType']").find("option").each(function(n,item){
			 if(json.feeType!=$(this).val()){
				 $(this).remove();	
			 }
		 })
		 $("select[name='cardpCode']").find("option").each(function(n,item){
			 if(json.cardpName==$(this).text()){
				 $(this).attr("selected","selected")
			 }
		 })
		 $("select[name='feeType']").val(json.feeType);
	 }
	 else{
		 $("input[name='flag']").val("0")//新增标识 
	 }
	
 }
 
 function addRequired(sel){
	 var value=$(sel).val();
	 if(value=="4"){
		$("select[name='appType']").addClass("required");
		$("select[name='appKindId']").addClass("required");
		$("select[name='appType']").removeAttr("disabled",true);
		$("select[name='appKindId']").removeAttr("disabled",true);
		return false;
	 }else if(value=="1"){
		 alertMsg.correct("工本费无需选择应用选项")
		 $("select[name='appType']").attr("disabled",true);
		 $("select[name='appKindId']").attr("disabled",true);
	 }
	 else{
		$("select[name='appType']").removeClass("required");
		$("select[name='appKindId']").removeClass("required");
		$("select[name='appType']").removeAttr("disabled",true);
		$("select[name='appKindId']").removeAttr("disabled",true);
	 }
	 
 }
</script>
<div class="pageContent">
	<form method="post" action="appChargeDef/addOrUpdateChargeDef" class="pageForm required-validate" onsubmit="return validateCallback(this,dialogAjaxDone);">
		<div class="pageFormContent" layoutH="58">
			<div id=userNo>
			<p >
				<label>交易名称：</label>
				<input name="feeItemName"  type="text" size="30" class="validRequired validDefinitionName"/>
				<input name="flag"  type="hidden" size="30" class="" />
				<input name="feeRuleId"  type="hidden" size="30" class="" />
				<input name="feeRulesId"  type="hidden" size="30" class="" />
			</p>
			</div>
			<p>
				<label>卡产品：</label>
				<select class="validRequired" name="cardpCode" >
				
				</select>
			</p>
			<p>
				<label>费用类型：</label>
				<select class="validRequired" name="feeType" onchange="addRequired(this)">
					<option value="">请选择</option>
					<option value="0">本金</option>
					<option value="1">工本费</option>
					<option value="2">交易手续费</option>
					<option value="3">租金</option>
					<option value="4">押金</option>
				</select>
			</p>
			<p>
				<label>应用分类：</label>
				<select  name="appKindId" onchange="showAppTypeByAppKindId(this)" class="">
			
				</select>
			</p>
			<p>
				<label>应用类型：</label>
				<select  name="appType" class="">
			
				</select>
			</p>
			
			<p>
				<label>收费金额：</label>
				<input name="feeBln"  type="text" size="30" class="validRequired validCharge">
			</P>
			<p>
				<label>有效期(起)：</label>
				<input  name="validStartDate" class="date validRequired validDateFrom" type="text" size="30"  />
			</p>
			<p>
				<label>有效期(止)：</label>
				<input  name="validEndDate"  type="text" size="30" class="date validRequired validDateTo" />
				
			</p>
		</div>
		<div class="formBar">
			<ul> 
				<li>
				<div class="buttonActive"><div class="buttonContent"><button id="submit" type="submit" class="valid">提交</button></div></div>
				</li>
			</ul>
		</div>
	</form>
</div>